var wineApp = wineApp || {};
wineApp.search = (function() {
    var params = $.url().param();
    var content = params["content"];
    var pageSize = 100;
    var resourceURL = wineApp.tool.getResourceURL();
    var initPage = function() {
        loadSearchContent();
        //wineApp.common.initBanner();

    }

    var loadSearchContent = function() {

        if (_.isEmpty(content)) return;
        $(".wine_toptitle p").html("搜索 - " + content);
        $(".wine_not_found").removeClass('wine_hidden');
        var ajaxUrl = wineApp.CONFIG.API.searchcontent
        wineApp.ajax.post(ajaxUrl, {
            content: content
        }).done(onSuccess);
    }

    var onSuccess = function(data) {

        var template = '<dl>' +
            '<dt><a href="jz_detail.html?jzid=${id}"><img src="${img}"></a></dt>' +
            '<dd>' +
            '<a href="wine_detail.html?wineId=${id}">' +
            '<p>${title}</p>会员价:<span style="color:#f60">${price}</span> 市场价:<span style="text-decoration: line-through">${oprice}</span></a>' +
            '</dd>' +
            '</dl>';
        if (data.list.length > 0) {
            $(".wine_not_found").addClass('wine_hidden');
        }
        $.each(data.list, function(index, jz) {
            jz.img = resourceURL + "/" + jz.titleimg;
            var tmp = _.template(template)(jz);
            $('.wine_bnjz').append(tmp);
        });
    }


    return {
        initPage: initPage
    }
})();

$(document).ready(function() {
    wineApp.common.initHeaderIcon(0, false);
    wineApp.search.initPage();
    wineApp.common.setSelectedMenu('');
});